<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

  <script>
      let obj = {
      name: 'chen',
      age: '21',
      address: '北京市',
      sayName: function() {
        console.log(this.name + this.age);
      }
    }
    Object.prototype.proto1 = function() {console.log('proto1');};
    Object.prototype.proto2 = 2;
    Object.defineProperty(obj, 'sex', {value: 'man', enumerable: false});

    // 1.for in
    // 遍历对象的可枚举属性，包括自有属性、继承自原型的属性
    for (let prop in obj) {
      console.log(prop + ':' + obj[prop]);
    }

    // 2.Object.keys()
    // 返回一个数组，元素均为对象自有可枚举的属性
    console.log(Object.keys(obj));

    // 3.Object.getOwnPropertyNames
    // 返回对象的自有属性，包括可枚举和不可枚举的属性
    console.log(Object.getOwnPropertyNames(obj));

  </script>

</head>
<body>
  
</body>
</html>